﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using _300Report.Global;

namespace _300Report.Pages
{
    public partial class SearchReportHistoryPage : PhoneApplicationPage
    {
        public static string SearcHistoryKey = "SearcHistoryKey";
        private SortedSet<string> source = null;
        public SearchReportHistoryPage()
        {
            InitializeComponent();
            source = Config.GetSearchReportHistory();
            if (source == null)
            {
                source = new SortedSet<string>();
                source.Add("暂无记录");
            }
           
            this.Loaded +=SearchReportHistoryPage_Loaded;
        }

        private void SearchReportHistoryPage_Loaded(object sender, RoutedEventArgs e)
        {
            this.SearchHistory.ItemsSource = source;
        }



        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            GC.Collect();
            base.OnNavigatedFrom(e);
        }

        /// <summary>
        /// 清除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Config.ClearIsolatedStorageSettings(SearcHistoryKey);
            this.SearchHistory.ItemsSource = new String[] { "暂无记录" };
        }

        private void SearchHistory_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            string roleName = e.AddedItems[0].ToString();
            Debug.WriteLine(roleName);
            NavigationHelper.NavigateGoBackExt(this.NavigationService, SearcHistoryKey, roleName);
        }

        protected override void OnBackKeyPress(CancelEventArgs e)
        {
            base.OnBackKeyPress(e);
        }
    }
}